package com.maila.xiaoaoschool.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.maila.xiaoaoschool.R;

import com.maila.xiaoaoschool.entity.MessageData;

import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**

 * Created by Administrator on 2017/9/26.
 */

public class MessageAdapter extends BaseAdapter {
    Context context;
    List<MessageData.DataBean> mdata;
    public MessageAdapter(Context context) {
        this.context = context;
        mdata=new ArrayList<>();
    }

    public List<MessageData.DataBean> getMdata() {
        return mdata;
    }

    public void setMdata(List<MessageData.DataBean> mdata) {
        this.mdata = mdata;
        notifyDataSetChanged();
    }
    public void addMdata(List<MessageData.DataBean> mdata) {
        this.mdata.addAll(mdata) ;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_message, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        if(mdata.get(i).getIs_read()==1){
            holder.orderCount.setVisibility(View.GONE);
        }else {
            holder.orderCount.setVisibility(View.VISIBLE);
        }
        holder.tvTitle.setText(mdata.get(i).getContent());
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.payment_iv)
        ImageView paymentIv;
        @BindView(R.id.order_count)
        TextView orderCount;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_title)
        TextView tvTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
